package edu.ccut.saturn.workflow.rollbackModule.code;

import edu.ccut.saturn.component.DefaultComponent;
import edu.ccut.saturn.component.IParameterContext;
import edu.ccut.saturn.component.SaturnData;
import edu.ccut.saturn.operation.Operation;
import edu.ccut.saturn.workflow.common.WorkFlowTools;

public class InsertParticipant extends DefaultComponent {
	@Override
	public void execute(IParameterContext parameterContext) throws Exception {
		String workitemId = (String)parameterContext.getParameterValue(0);
		String userId = (String)parameterContext.getParameterValue(1);
		String userName = WorkFlowTools.getUserNameById(userId, parameterContext.getConnection());
		String participantType = "user";
		SaturnData participantData = WorkFlowTools.getParticipantInstance();
		participantData.set("workitemid", Integer.valueOf(workitemId));
		participantData.set("participanttype", participantType);
		participantData.set("participant", userId);
		participantData.set("participant2", userName);
		Operation.dataBase().insert(participantData, parameterContext.getConnection());
	}
}